package com.itheima.controller;


import com.itheima.DTO.SubmitOrder;
import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.OderAndMember;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "体检预约")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 根据预约id查询预约信息
     * @param id
     * @return
     */
    @PostMapping("/findById")
    @ApiOperation("根据预约id查询预约信息")
    public Result findById(Integer id) {
        log.info("根据预约id查询预约信息...");
        OderAndMember data = orderService.findOrderAndMemberById(id);
        if (data == null){
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
        }else {
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS,data);
        }

    }

    @PostMapping("/submitOrder")
    @ApiOperation("提交预约")
    public Result submitOrder(@RequestBody SubmitOrder submitOrder) {
        String message = "";
        log.info("提交预约...");
        try {
            message = orderService.submitOrder(submitOrder);
            if (message != null){
                return new Result(true, MessageConstant.ORDER_SUCCESS,message);
            }else {
                return new Result(false, message);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, e.getMessage());
        }
//        return new Result(false, message);
    }
}
